package com.example.zyfapplication.utils;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Path;
import android.graphics.RectF;
import android.util.AttributeSet;
import android.view.View;

import androidx.annotation.Nullable;

import com.example.baeshelplibrary.utils.LogUtil;
import com.example.zyfapplication.R;
import com.example.zyfapplication.base.BaseApplication;

import java.util.ArrayList;
import java.util.List;


public class FaceView extends View {

    private Paint mPaint;
    private String mCorlor = "#42ed45";
    private List<RectF> mFace = new ArrayList<>();

    private static FaceView instance;

    public static FaceView getInstance() {
        if (instance == null) {
            instance = new FaceView(BaseApplication.getInstance());
        }
        return instance;
    }


    public FaceView(Context context) {
        super(context);
        init();
    }


    public FaceView(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        init();
    }

    public FaceView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        init();
    }

    private void init() {
        mPaint = new Paint();
        mPaint.setColor(Color.BLUE);
        mPaint.setStyle(Paint.Style.STROKE);
        mPaint.setStrokeWidth(6.0f);//设置线宽
        mPaint.setAlpha(255);
        mPaint.setAntiAlias(true);

    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        LogUtil.d("onDraw 会不会走啊");
        for (int i = 0; i < mFace.size(); i++) {
            canvas.drawRect(mFace.get(i), mPaint);
        }

    }

    public void setFaces(List<RectF> face) {
        mFace = face;
        for (int i = 0; i < mFace.size(); i++) {
            LogUtil.d("FaceView 左 ：" + mFace.get(i).left + "上 ：" + mFace.get(i).top + "右 ：" + mFace.get(i).right + "下 ：" + mFace.get(i).bottom);
        }
        invalidate();


    }


}
